package org.jsola.hr.helper;

import org.jsola.hr.dto.attendschedule.*;
import org.jsola.hr.service.IAttendScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class AttendScheduleTestHelper extends BaseTestHelper {

    @Autowired
    private IAttendScheduleService attendScheduleService;
    @Autowired
    private AttendShiftTestHelper attendShiftTestHelper;
    @Autowired
    private CycleDaysTestHelper cycleDaysTestHelper;
    @Autowired
    private AttendStaffScheduleTestHelper attendStaffScheduleTestHelper;

    /**
     *
     * @return
     */
    public String saveAttendScheduleExample() {
        AttendScheduleSaveDTO attendScheduleSaveDTO = this.getAttendScheduleSaveDTO();
        return attendScheduleService.save(attendScheduleSaveDTO, buildTokenUser());
    }

    public AttendScheduleSaveDTO getAttendScheduleSaveDTO() {

        AttendScheduleSaveDTO attendScheduleSaveDTO = new AttendScheduleSaveDTO();

        // 考勤班次
        List<AttendShiftSaveDTO> attendShiftList = attendShiftTestHelper.getAttendShiftList();
        // 排班周期
        List<AttendCycleSaveDTO> attendCycleList = cycleDaysTestHelper.getAttendCycleList();
        // 人员排班
        List<AttendStaffScheduleDTO> attendStaffScheduleList = attendStaffScheduleTestHelper.getAttendStaffScheduleList();

        attendScheduleSaveDTO.setAttendShiftList(attendShiftList);
        attendScheduleSaveDTO.setAttendCycleList(attendCycleList);
        attendScheduleSaveDTO.setAttendStaffScheduleList(attendStaffScheduleList);

        return attendScheduleSaveDTO;
    }

    public AttendScheduleUpdateDTO getAttendScheduleUpdateDTO() {

        AttendScheduleUpdateDTO attendScheduleUpdateDTO = new AttendScheduleUpdateDTO();

        attendScheduleUpdateDTO.setAttendPlanId("");
        attendScheduleUpdateDTO.setAttendShiftList(this.getAttendShiftList());
        attendScheduleUpdateDTO.setAttendCycleList(this.getAttendCycleList());
        attendScheduleUpdateDTO.setAttendStaffScheduleList(this.getAttendStaffScheduleList());

        return attendScheduleUpdateDTO;
    }

    /**
     * 考勤班次
     *
     * @return
     */
    public List<AttendShiftSaveDTO> getAttendShiftList() {

        List<AttendShiftSaveDTO> attendShiftList = new ArrayList<>();

        AttendShiftSaveDTO shift1 = new AttendShiftSaveDTO();
        // 班次名称
        shift1.setName("早");
        // 考勤时段
        AttendPeriodDTO period1 = new AttendPeriodDTO();
        period1.setStartPeriod("08:00");
        period1.setEndPeriod("09:00");
        period1.setType(1);

        List<AttendPeriodDTO> attendPeriodList = new ArrayList<>();
        attendPeriodList.add(period1);
        shift1.setAttendPeriodList(attendPeriodList);

        // 允许迟到早退 ; 1-允许,0-不允许
        shift1.setIsAllowedLateEarly(1);
        // 班允许早退(分钟)
        shift1.setLateMinute(2);
        // 允许晚走晚到 ; 1-允许,0-不允许
        shift1.setIsAllowLateLate(1);
        // 下班晚走(分钟)
        shift1.setOffWorkLateMinute(2);
        // 上班晚到(分钟)
        shift1.setOnWorkLateMinute(2);
        // 最早上班打卡时间(分钟)
        shift1.setEarliestPunchTime("100");
        // 最晚下班打卡时间(分钟)
        shift1.setLatestPunchTime("100");
        // 班是否需要打卡 : 1-是,0-否
        shift1.setAfterWorkNeedPunch(1);
        // 班允许早退(分钟)
        shift1.setEarlyMinute(4);

        attendShiftList.add(shift1);

        return attendShiftList;
    }

    /**
     * 排班周期
     *
     * @return
     */
    public List<AttendCycleSaveDTO> getAttendCycleList() {

        List<AttendCycleSaveDTO> attendCycleList = new ArrayList<>();

        AttendCycleSaveDTO cycle1 = new AttendCycleSaveDTO();

        List<CycleDaysDTO> cycleDays = new ArrayList<>();

        CycleDaysDTO days1 = new CycleDaysDTO();
        days1.setDaysName("第1天");
        days1.setShiftName("早");
        cycleDays.add(days1);

        CycleDaysDTO days2 = new CycleDaysDTO();
        days2.setDaysName("第2天");
        days2.setShiftName("早");
        cycleDays.add(days2);

        CycleDaysDTO days3 = new CycleDaysDTO();
        days3.setDaysName("第3天");
        days3.setShiftName("休");
        cycleDays.add(days3);

        cycle1.setCycleName("周期一");
        cycle1.setCycleDays(cycleDays);

        attendCycleList.add(cycle1);

        return attendCycleList;
    }

    public List<AttendStaffScheduleDTO> getAttendStaffScheduleList() {

        List<AttendStaffScheduleDTO> attendStaffScheduleList = new ArrayList<>();

        AttendStaffScheduleDTO staff1 = new AttendStaffScheduleDTO();

        staff1.setEmpInfoId("xxxx");
        staff1.setEmpInfoName("xxxx");
        staff1.setYearMonthDay("2019-12-20");
        staff1.setShiftName("早");
        attendStaffScheduleList.add(staff1);

        AttendStaffScheduleDTO staff2 = new AttendStaffScheduleDTO();

        staff2.setEmpInfoId("xxxx");
        staff2.setEmpInfoName("xxxx");
        staff2.setYearMonthDay("2019-12-21");
        staff2.setShiftName("早");
        attendStaffScheduleList.add(staff2);

        AttendStaffScheduleDTO staff3 = new AttendStaffScheduleDTO();

        staff3.setEmpInfoId("xxxx");
        staff3.setEmpInfoName("xxxx");
        staff3.setYearMonthDay("2019-12-21");
        staff3.setShiftName("休");
        attendStaffScheduleList.add(staff3);

        return attendStaffScheduleList;
    }

}